package mianyang.zhangsan.com.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import mianyang.zhangsan.com.mapper.ClazzMapper;
import mianyang.zhangsan.com.pojo.Clazz;
import mianyang.zhangsan.com.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("clazzService")
public class ClazzServiceImpl implements ClazzService {
    @Autowired
    private ClazzMapper clazzMapper;

    /**
     * 分页查询
     * @param page
     * @param size
     * @param clazzName
     * @return
     */
    @Override
    public Page<Clazz> queryByPage(int page, int size, String clazzName) {
        QueryWrapper<Clazz> wrapper = new QueryWrapper<>();
        if (!"".equals(clazzName) && clazzName != null){
            wrapper.eq("name", clazzName);
            return clazzMapper.selectPage(new Page<>(page, size), wrapper);
        }
        return clazzMapper.selectPage(new Page<>(page, size), null);
    }

    /**
     * 添加班级信息
     * @param clazz
     */
    @Override
    public void addClazz(Clazz clazz) {
        clazzMapper.insert(clazz);
    }

    /**
     * 删除班级信息
     * @param id
     */
    @Override
    public void deleteClazz(int id) {
        QueryWrapper<Clazz> wrapper = new QueryWrapper<>();
        wrapper.eq("id", id);
        clazzMapper.delete(wrapper);
    }

    /**
     * 查询所有的班级信息
     * @return
     */
    @Override
    public List<Clazz> queryInfoAll() {
        return clazzMapper.selectList(null);
    }
}
